<template>
  <div class="box_yj sectionss" ref="parent">
    <span></span>

    <div class="section-header">三医人才供应占比</div>
    <div id="charts" ref="charts" :style="chartsDom" v-show="jz"></div>
             <animae-jz   :style="chartsDom" v-if="!jz"></animae-jz>
  </div>
</template>
<script>
import { get_TalentIn_supplyanddemand } from '@/api/data'
export default {
  data() {
    return {
      chartsDom: {},
      data: null,
      jz:false
    }
  },
  props: ['height','dateProp'],
  computed: {
    setStyle: {
      get() {
        return this.$refs.parent.offsetWidth
      },
      set(val) {
        this.chartsDom = {
        width: val - 30 + 'px',
        height: this.height - 30 - 31 + 'px',
        'z-index': 100,
        position: 'relative',
        // 'background-color': 'red'
      }
      }
    },
    chartData() {
      let tempData = [];
      Object.keys(this.data).forEach(v=>{
        tempData.push({
          name: v === 'PlanNumber' ? '总人才数' : '三医人才数',
          value: this.data[v]
        });
      });
      return tempData;
    },
    titleData() {
      return {
        total: this.data.PlanNumber,
        CompleteNumber: this.data.CompleteNumber,
        percent: Math.round((this.data.CompleteNumber/this.data.PlanNumber)*100)+'%'
      }
    }
  },
  mounted() {
    this.setStyle = this.setStyle;
    this.$nextTick(_=>{
      this.init();
    })
  },
  methods: {
    init(){
      this.jz=false
      console.log(this.dateProp)
      get_TalentIn_supplyanddemand(this.dateProp)
      .then(({data:{data}})=>{
        this.jz=true

        // this.data = data[0];
		// this.data = {
		// 	CompleteNumber: data[0]['value'],
		// 	PlanNumber: Number(data[0]['value']) + Number(data[1]['value']),
		// }
        // this.data = data.length ? data[0] : {PlanNumber:111,CompleteNumber:222}
        this.$nextTick(_=>{
          this.drawChart(data);
        })
      })
    },
    drawChart(dataa) {
      let option = {
          color: ['#87f7cf', '#f7f494', '#fc97af', '#f7c5a0', '#72ccff'],
          tooltip: {
              trigger: 'axis',
              axisPointer: {
                  type: 'shadow'
              }
          },
        
          grid: {
            top: '10%',
            left: '13%',
            right: '3%',
            bottom: '13%'
          },
          legend: {
              data: ['需求','供应'],
              orient: 'horizontal',
              textStyle: {
                color: 'rgba(255,255,255,1)'
              },
              left: 'right',
              width: this.setStyle - 30,
              itemWidth: 10,
              itemHeight: 10,
              // top: 10
          },
          xAxis: [
              {
                  type: 'category',
                  axisTick: {show: false},
                  data: dataa.gong.map(item=>item.name),
                  axisLabel: {
                    textStyle: {
                      color: '#8ebafb'
                    }
                  },
                  axisLine: {
                    lineStyle: {
                      color: 'rgba(255,255,255,.5)'
                    }
                  }
              }
          ],
          yAxis: [
              {
                  type: 'value',
                  splitLine: {show: false},
                  axisTick: {show: false},
                  axisLabel: {
                    textStyle: {
                      color: '#8ebafb'
                    }
                  },
                  axisLine: {
                    lineStyle: {
                      color: 'rgba(255,255,255,.5)'
                    }
                  }
              }
          ],
          series: [
            {
            name: '供应',
            type: 'bar',
            data: dataa.gong.map(v=>v.value)
             },
              {
            name: '需求',
            type: 'bar',
            data: dataa.xu.map(v=>v.value)
             },
          ]
      };
      let chartsInit = this.$echarts.init(this.$refs.charts);
      chartsInit.setOption(option);
    }
  },
}
</script>
<style lang="stylus" scoped>
  .section
    width 100%
    height 100%
    margin-top 20px
</style>